﻿using System;

namespace COC.Webs
{
    /// <summary>
    /// 1.从网络url获取报文
    /// 2.将取得的报文中有用的部分
    /// 3.将该部分xml解析为一个二维数组存储
    /// 4.将数组作为表格显示在界面上
    /// </summary>
    class MakeData
    {
    
        public string TroopsData(string troops)
        {
            string httpData = DataGetHttp(troops);
            //httpData = httpData.GetElementById("archer-table-2");
            return ClanDataParser.Parse(httpData, troops);
        }


    /// <summary>
    /// 获取从网络url过来的全部报文
    /// </summary>
    /// <param name="troops">兵种英文名</param>
    /// <returns>网络全部报文</returns>
        public string DataGetHttp(string troops)
        {
            troops = "http://clashofclans.wikia.com/wiki/" + troops;
            GetHttpData myHttpData = new GetHttpData();
            string httpData = myHttpData.HttpGet(troops,null);
            //Console.WriteLine(httpData); //这条语句执行速度奇慢无比，因为数据太长了，注释掉
            return httpData;
        }

        /// <summary>
        /// 截取报文中的需要的表格
        /// </summary>
        /// <param name="httpData">全部报文</param>
        /// <param name="cutStartSign">截取的开始标志</param>
        /// <param name="cutEndSign">截取的结束标志</param>
        /// <returns>返回需要的表格的报文</returns>
        public string CutHttpData(string httpData,string cutStartSign,String cutEndSign)
        {
            string cutHttpData = null;
            int IndexofA = httpData.IndexOf(cutStartSign);
            int IndexofB = httpData.IndexOf(cutEndSign);
            cutHttpData = httpData.Substring(IndexofA + 1, IndexofB - IndexofA - 1);

            return cutHttpData;
        }

        /// <summary>
        /// 将表格报文转化为二维数组
        /// </summary>
        /// <param name="cutHttpData">表格报文</param>
        /// <returns>处理完的二维数组</returns>
        //public string[][] BingData(string cutHttpData)
        //{
        //    string[][] bingData = null;

        //    //获取数组的横纵长度
        //    int itemNum;
        //    int levelNum;



        //    return bingData;
        //}
    }
}
